package com.jarveis.frame.task;

import java.io.Serializable;
import java.util.Calendar;

/**
 * 计划实体类
 * 
 * @author liuguojun
 */
public class TaskInfo implements Serializable {

	private String code;
	private String sleepTime; // 任务执行完成后暂停时间
	private ITask.Status status; // 是否运行
	private long runTime; // 下一次的运行时间

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getSleepTime() {
		return sleepTime;
	}

	public void setSleepTime(String sleepTime) {
		this.sleepTime = sleepTime;
	}

	public ITask.Status getStatus() {
		return status;
	}

	public void setStatus(ITask.Status status) {
		this.status = status;
		if (status == ITask.Status.Sleep || runTime > 0L) {
			setRunTime(Calendar.getInstance().getTimeInMillis());
		}
	}

	public long getRunTime() {
		return runTime;
	}

	public void setRunTime(long runTime) {
		if (runTime > 0L) {
			int len = sleepTime.length();
			char c = sleepTime.charAt(len - 1);
			int n = Integer.parseInt(sleepTime.substring(0, len - 1), 10);
			
			if (c == 's') {
				runTime = runTime + n * 1000;
			} else if (c == 'm') {
				runTime = runTime + n * 60000;
			} else if (c == 'h') {
				runTime = runTime + n * 3600000;
			} else if (c == 'd') {
				runTime = runTime + n * 86400000;
			}
		}

		this.runTime = runTime;
	}
}
